** Korea Education and Social Stratification and Mobility Survey 2011
** data management and clearning


** 01. Reading data **

cap log close
clear
use /*read your data here*/  

** 02. Consructing variables **

rename id pid
label var pid "person id"

label var year "survey year"

rename birthy birthyr

ge country=410

label var sex "sex"
label define sex 1 "male" 2 "female"
label values sex sex

label var birthyr "birth year"

rename p0020101 nbro
rename p0020102 nsis
rename p0020103 birthorder
replace nbro=1 if nbro==0
replace nbro=. if nbro==99
replace nsis=. if nsis==99
replace birthorder=. if birthorder==99
replace nbro = nbro-1 if sex==1
replace nsis = nsis-1 if sex==2
label var nbro "number of brothers"
label var nsis "number of sisters"
label var birthorder "my birth order"
ge nsibs = nbro + nsis
label var nsibs "number of siblings"

ge educ_yrs=.
ge educ=.

replace educ_yrs=0 if p0050000==2
replace educ=1 if p0050000==2

replace educ_yrs=3 if p0050000==1 & p0050100==2
replace educ=1 if p0050000==1 & p0050100==2

replace educ_yrs=6 if (p0050000==1 & p0050100==1) & p0060000==2
replace educ=2 if (p0050000==1 & p0050100==1) & p0060000==2

replace educ_yrs=7.5 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100>1 & p0060100!=.)
replace educ=2 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100>1 & p0060100!=.)

replace educ_yrs=9 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & p0070001==2
replace educ=3 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & p0070001==2

replace educ_yrs=10.5 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201>1 & p0070201!=.)
replace educ=3 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201>1 & p0070201!=.)

replace educ_yrs=12 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & p0080001==2
replace educ=4 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & p0080001==2

replace educ_yrs=13 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==1 & p0080901>1 & p0080901!=.)
replace educ=4 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==1 & p0080901>1 & p0080901!=.)

replace educ_yrs=14 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==1 & p0080901==1)
replace educ=5 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==1 & p0080901==1)

replace educ_yrs=14 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901>1 & p0080901!=.)
replace educ=4 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901>1 & p0080901!=.)

replace educ_yrs=16 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901==1) & p0090000==2
replace educ=6 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901==1) & p0090000==2

replace educ_yrs=17 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901==1) & (p0090000==1 & p0090201<3 & p0090401>1)
replace educ=6 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901==1) & (p0090000==1 & p0090201<3 & p0090401>1)

replace educ_yrs=18 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901==1) & (p0090000==1 & p0090201<3 & p0090401==1)
replace educ=7 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901==1) & (p0090000==1 & p0090201<3 & p0090401==1)

replace educ_yrs=18 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901==1) & (p0090000==1 & p0090201==3 & p0090401>1)
replace educ=7 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901==1) & (p0090000==1 & p0090201==3 & p0090401>1)

replace educ_yrs=20 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901==1) & (p0090000==1 & p0090201==3 & p0090401==1)
replace educ=7 if (p0050000==1 & p0050100==1) & (p0060000==1 & p0060100==1) & (p0070001==1 & p0070201==1) & (p0080001==1 & p0080604==2 & p0080901==1) & (p0090000==1 & p0090201==3 & p0090401==1)

label var educ_yrs "years of schooling"
label var educ "highest level of schooling completed"
label define educ 1 "less than primary" 2 "primary" 3 "lower secondary" 4 "upper secondary" 5 "junior college" 6 "4-year college" 7 "postgraduate"
label values educ educ


* parental education
recode q0230101 (1=0) (2=1) (3=3) (4=6) (5=7.5) (6=9) (7=10.5) (8=12) (9=13) (10=14) (11=14) (12=16) (13=18) (14=20) (15/99=.)
rename q0230101 faeduc_yrs
recode q0230201 (1=0) (2=1) (3=3) (4=6) (5=7.5) (6=9) (7=10.5) (8=12) (9=13) (10=14) (11=14) (12=16) (13=18) (14=20) (15/99=.)
rename q0230201 maeduc_yrs
label var faeduc_yrs "father's years of schooling"
label var maeduc_yrs "mother's years of schooling"

* father's occupation
rename q0220113 faocc
label var faocc "father's occupation at age 14"

ge faisei=.
replace	faisei=	77	if	faocc==	11
replace	faisei=	77	if	faocc==	12
replace	faisei=	58	if	faocc==	13
replace	faisei=	70	if	faocc==	21
replace	faisei=	67	if	faocc==	22
replace	faisei=	67	if	faocc==	23
replace	faisei=	61	if	faocc==	24
replace	faisei=	51	if	faocc==	30
replace	faisei=	69	if	faocc==	111
replace	faisei=	78	if	faocc==	112
replace	faisei=	65	if	faocc==	113
replace	faisei=	71	if	faocc==	120
replace	faisei=	69	if	faocc==	131
replace	faisei=	68	if	faocc==	132
replace	faisei=	71	if	faocc==	133
replace	faisei=	56	if	faocc==	134
replace	faisei=	69	if	faocc==	135
replace	faisei=	85	if	faocc==	141
replace	faisei=	74	if	faocc==	142
replace	faisei=	43	if	faocc==	143
replace	faisei=	85	if	faocc==	144
replace	faisei=	85	if	faocc==	145
replace	faisei=	77	if	faocc==	151
replace	faisei=	69	if	faocc==	152
replace	faisei=	66	if	faocc==	153
replace	faisei=	43	if	faocc==	154
replace	faisei=	66	if	faocc==	155
replace	faisei=	66	if	faocc==	156
replace	faisei=	66	if	faocc==	157
replace	faisei=	68	if	faocc==	161
replace	faisei=	69	if	faocc==	162
replace	faisei=	69	if	faocc==	163
replace	faisei=	69	if	faocc==	164
replace	faisei=	69	if	faocc==	165
replace	faisei=	85	if	faocc==	171
replace	faisei=	51	if	faocc==	172
replace	faisei=	53	if	faocc==	173
replace	faisei=	65	if	faocc==	181
replace	faisei=	65	if	faocc==	182
replace	faisei=	64	if	faocc==	183
replace	faisei=	64	if	faocc==	184
replace	faisei=	49	if	faocc==	211
replace	faisei=	50	if	faocc==	212
replace	faisei=	55	if	faocc==	213
replace	faisei=	52	if	faocc==	220
replace	faisei=	49	if	faocc==	231
replace	faisei=	46	if	faocc==	232
replace	faisei=	54	if	faocc==	233
replace	faisei=	51	if	faocc==	234
replace	faisei=	52	if	faocc==	235
replace	faisei=	57	if	faocc==	236
replace	faisei=	50	if	faocc==	237
replace	faisei=	49	if	faocc==	238
replace	faisei=	51	if	faocc==	241
replace	faisei=	51	if	faocc==	242
replace	faisei=	49	if	faocc==	243
replace	faisei=	38	if	faocc==	251
replace	faisei=	38	if	faocc==	252
replace	faisei=	38	if	faocc==	253
replace	faisei=	55	if	faocc==	261
replace	faisei=	55	if	faocc==	262
replace	faisei=	55	if	faocc==	263
replace	faisei=	43	if	faocc==	271
replace	faisei=	38	if	faocc==	272
replace	faisei=	52	if	faocc==	281
replace	faisei=	54	if	faocc==	282
replace	faisei=	52	if	faocc==	283
replace	faisei=	54	if	faocc==	291
replace	faisei=	59	if	faocc==	292
replace	faisei=	56	if	faocc==	293
replace	faisei=	45	if	faocc==	311
replace	faisei=	45	if	faocc==	312
replace	faisei=	45	if	faocc==	313
replace	faisei=	45	if	faocc==	314
replace	faisei=	51	if	faocc==	315
replace	faisei=	36	if	faocc==	316
replace	faisei=	39	if	faocc==	317
replace	faisei=	39	if	faocc==	318
replace	faisei=	46	if	faocc==	321
replace	faisei=	52	if	faocc==	322
replace	faisei=	49	if	faocc==	323
replace	faisei=	38	if	faocc==	411
replace	faisei=	29	if	faocc==	412
replace	faisei=	30	if	faocc==	413
replace	faisei=	54	if	faocc==	414
replace	faisei=	38	if	faocc==	415
replace	faisei=	30	if	faocc==	416
replace	faisei=	30	if	faocc==	421
replace	faisei=	34	if	faocc==	422
replace	faisei=	19	if	faocc==	431
replace	faisei=	34	if	faocc==	432
replace	faisei=	50	if	faocc==	441
replace	faisei=	42	if	faocc==	442
replace	faisei=	40	if	faocc==	443
replace	faisei=	40	if	faocc==	444
replace	faisei=	43	if	faocc==	511
replace	faisei=	43	if	faocc==	512
replace	faisei=	37	if	faocc==	513
replace	faisei=	43	if	faocc==	521
replace	faisei=	43	if	faocc==	522
replace	faisei=	43	if	faocc==	530
replace	faisei=	23	if	faocc==	611
replace	faisei=	23	if	faocc==	612
replace	faisei=	23	if	faocc==	613
replace	faisei=	23	if	faocc==	614
replace	faisei=	23	if	faocc==	615
replace	faisei=	23	if	faocc==	616
replace	faisei=	23	if	faocc==	617
replace	faisei=	28	if	faocc==	618
replace	faisei=	22	if	faocc==	620
replace	faisei=	28	if	faocc==	630
replace	faisei=	30	if	faocc==	711
replace	faisei=	30	if	faocc==	712
replace	faisei=	34	if	faocc==	713
replace	faisei=	29	if	faocc==	714
replace	faisei=	31	if	faocc==	721
replace	faisei=	35	if	faocc==	722
replace	faisei=	34	if	faocc==	731
replace	faisei=	34	if	faocc==	732
replace	faisei=	40	if	faocc==	733
replace	faisei=	38	if	faocc==	741
replace	faisei=	28	if	faocc==	742
replace	faisei=	29	if	faocc==	743
replace	faisei=	40	if	faocc==	744
replace	faisei=	30	if	faocc==	751
replace	faisei=	33	if	faocc==	752
replace	faisei=	36	if	faocc==	753
replace	faisei=	31	if	faocc==	754
replace	faisei=	35	if	faocc==	811
replace	faisei=	30	if	faocc==	812
replace	faisei=	22	if	faocc==	813
replace	faisei=	27	if	faocc==	814
replace	faisei=	35	if	faocc==	815
replace	faisei=	32	if	faocc==	816
replace	faisei=	26	if	faocc==	817
replace	faisei=	36	if	faocc==	821
replace	faisei=	30	if	faocc==	822
replace	faisei=	30	if	faocc==	823
replace	faisei=	29	if	faocc==	824
replace	faisei=	38	if	faocc==	825
replace	faisei=	30	if	faocc==	826
replace	faisei=	29	if	faocc==	827
replace	faisei=	29	if	faocc==	828
replace	faisei=	26	if	faocc==	829
replace	faisei=	31	if	faocc==	831
replace	faisei=	34	if	faocc==	832
replace	faisei=	30	if	faocc==	833
replace	faisei=	36	if	faocc==	841
replace	faisei=	34	if	faocc==	842
replace	faisei=	26	if	faocc==	843
replace	faisei=	32	if	faocc==	844
replace	faisei=	16	if	faocc==	911
replace	faisei=	23	if	faocc==	912
replace	faisei=	27	if	faocc==	913
replace	faisei=	23	if	faocc==	914
replace	faisei=	23	if	faocc==	915
replace	faisei=	16	if	faocc==	920
replace	faisei=	20	if	faocc==	930
replace	faisei=	21	if	faocc==	941
replace	faisei=	29	if	faocc==	942
replace	faisei=	56	if	faocc==	943
replace	faisei=	40	if	faocc==	944
replace	faisei=	.	if	faocc==	999
label var faisei "father's occupational status (ISEI) at age 14"

ge faclass=.
replace	faclass=	1	if	faocc==	11
replace	faclass=	1	if	faocc==	12
replace	faclass=	2	if	faocc==	13
replace	faclass=	1	if	faocc==	21
replace	faclass=	1	if	faocc==	22
replace	faclass=	1	if	faocc==	23
replace	faclass=	1	if	faocc==	24
replace	faclass=	2	if	faocc==	30
replace	faclass=	1	if	faocc==	111
replace	faclass=	1	if	faocc==	112
replace	faclass=	1	if	faocc==	113
replace	faclass=	1	if	faocc==	120
replace	faclass=	1	if	faocc==	131
replace	faclass=	1	if	faocc==	132
replace	faclass=	1	if	faocc==	133
replace	faclass=	2	if	faocc==	134
replace	faclass=	1	if	faocc==	135
replace	faclass=	1	if	faocc==	141
replace	faclass=	1	if	faocc==	142
replace	faclass=	2	if	faocc==	143
replace	faclass=	1	if	faocc==	144
replace	faclass=	1	if	faocc==	145
replace	faclass=	1	if	faocc==	151
replace	faclass=	2	if	faocc==	152
replace	faclass=	2	if	faocc==	153
replace	faclass=	2	if	faocc==	154
replace	faclass=	2	if	faocc==	155
replace	faclass=	1	if	faocc==	156
replace	faclass=	1	if	faocc==	157
replace	faclass=	1	if	faocc==	161
replace	faclass=	1	if	faocc==	162
replace	faclass=	2	if	faocc==	163
replace	faclass=	2	if	faocc==	164
replace	faclass=	2	if	faocc==	165
replace	faclass=	1	if	faocc==	171
replace	faclass=	2	if	faocc==	172
replace	faclass=	2	if	faocc==	173
replace	faclass=	2	if	faocc==	181
replace	faclass=	2	if	faocc==	182
replace	faclass=	2	if	faocc==	183
replace	faclass=	2	if	faocc==	184
replace	faclass=	2	if	faocc==	211
replace	faclass=	2	if	faocc==	212
replace	faclass=	2	if	faocc==	213
replace	faclass=	2	if	faocc==	220
replace	faclass=	2	if	faocc==	231
replace	faclass=	2	if	faocc==	232
replace	faclass=	2	if	faocc==	233
replace	faclass=	2	if	faocc==	234
replace	faclass=	2	if	faocc==	235
replace	faclass=	2	if	faocc==	236
replace	faclass=	2	if	faocc==	237
replace	faclass=	2	if	faocc==	238
replace	faclass=	2	if	faocc==	241
replace	faclass=	2	if	faocc==	242
replace	faclass=	2	if	faocc==	243
replace	faclass=	3	if	faocc==	251
replace	faclass=	3	if	faocc==	252
replace	faclass=	3	if	faocc==	253
replace	faclass=	2	if	faocc==	261
replace	faclass=	2	if	faocc==	262
replace	faclass=	2	if	faocc==	263
replace	faclass=	3	if	faocc==	271
replace	faclass=	3	if	faocc==	272
replace	faclass=	2	if	faocc==	281
replace	faclass=	2	if	faocc==	282
replace	faclass=	2	if	faocc==	283
replace	faclass=	3	if	faocc==	291
replace	faclass=	2	if	faocc==	292
replace	faclass=	2	if	faocc==	293
replace	faclass=	3	if	faocc==	311
replace	faclass=	3	if	faocc==	312
replace	faclass=	3	if	faocc==	313
replace	faclass=	3	if	faocc==	314
replace	faclass=	3	if	faocc==	315
replace	faclass=	3	if	faocc==	316
replace	faclass=	3	if	faocc==	317
replace	faclass=	3	if	faocc==	318
replace	faclass=	3	if	faocc==	321
replace	faclass=	3	if	faocc==	322
replace	faclass=	3	if	faocc==	323
replace	faclass=	3	if	faocc==	411
replace	faclass=	8	if	faocc==	412
replace	faclass=	2	if	faocc==	413
replace	faclass=	8	if	faocc==	414
replace	faclass=	3	if	faocc==	415
replace	faclass=	8	if	faocc==	416
replace	faclass=	8	if	faocc==	421
replace	faclass=	9	if	faocc==	422
replace	faclass=	9	if	faocc==	431
replace	faclass=	3	if	faocc==	432
replace	faclass=	8	if	faocc==	441
replace	faclass=	8	if	faocc==	442
replace	faclass=	9	if	faocc==	443
replace	faclass=	9	if	faocc==	444
replace	faclass=	3	if	faocc==	511
replace	faclass=	3	if	faocc==	512
replace	faclass=	3	if	faocc==	513
replace	faclass=	3	if	faocc==	521
replace	faclass=	3	if	faocc==	522
replace	faclass=	3	if	faocc==	530
replace	faclass=	10	if	faocc==	611
replace	faclass=	10	if	faocc==	612
replace	faclass=	10	if	faocc==	613
replace	faclass=	10	if	faocc==	614
replace	faclass=	10	if	faocc==	615
replace	faclass=	10	if	faocc==	616
replace	faclass=	10	if	faocc==	617
replace	faclass=	10	if	faocc==	618
replace	faclass=	10	if	faocc==	620
replace	faclass=	10	if	faocc==	630
replace	faclass=	9	if	faocc==	711
replace	faclass=	8	if	faocc==	712
replace	faclass=	8	if	faocc==	713
replace	faclass=	8	if	faocc==	714
replace	faclass=	8	if	faocc==	721
replace	faclass=	8	if	faocc==	722
replace	faclass=	8	if	faocc==	731
replace	faclass=	8	if	faocc==	732
replace	faclass=	8	if	faocc==	733
replace	faclass=	8	if	faocc==	741
replace	faclass=	9	if	faocc==	742
replace	faclass=	9	if	faocc==	743
replace	faclass=	8	if	faocc==	744
replace	faclass=	8	if	faocc==	751
replace	faclass=	8	if	faocc==	752
replace	faclass=	8	if	faocc==	753
replace	faclass=	8	if	faocc==	754
replace	faclass=	9	if	faocc==	811
replace	faclass=	9	if	faocc==	812
replace	faclass=	9	if	faocc==	813
replace	faclass=	9	if	faocc==	814
replace	faclass=	8	if	faocc==	815
replace	faclass=	8	if	faocc==	816
replace	faclass=	8	if	faocc==	817
replace	faclass=	9	if	faocc==	821
replace	faclass=	9	if	faocc==	822
replace	faclass=	9	if	faocc==	823
replace	faclass=	9	if	faocc==	824
replace	faclass=	9	if	faocc==	825
replace	faclass=	9	if	faocc==	826
replace	faclass=	9	if	faocc==	827
replace	faclass=	9	if	faocc==	828
replace	faclass=	9	if	faocc==	829
replace	faclass=	9	if	faocc==	831
replace	faclass=	9	if	faocc==	832
replace	faclass=	9	if	faocc==	833
replace	faclass=	9	if	faocc==	841
replace	faclass=	9	if	faocc==	842
replace	faclass=	9	if	faocc==	843
replace	faclass=	9	if	faocc==	844
replace	faclass=	9	if	faocc==	911
replace	faclass=	9	if	faocc==	912
replace	faclass=	9	if	faocc==	913
replace	faclass=	9	if	faocc==	914
replace	faclass=	9	if	faocc==	915
replace	faclass=	10	if	faocc==	920
replace	faclass=	9	if	faocc==	930
replace	faclass=	9	if	faocc==	941
replace	faclass=	9	if	faocc==	942
replace	faclass=	7	if	faocc==	943
replace	faclass=	8	if	faocc==	944
replace	faclass=	.	if	faocc==	999

replace faclass=6 if faclass==3 & (q0220106==1 | q0220106>4) & q0220106!=.
replace faclass=10 if q0220112==1 | q0220112==2
replace faclass=4 if q0220111==4 & faclass!=1 & faclass!=10
replace faclass=5 if q0220111==5 & faclass!=10
replace faclass=11 if faclass==10 & ((q0220111==4 | q0220111==5) | (q0220106==2 | q0220106==4))

label var faclass "father's class (EGP) at age 14"
label define class11 1 "I: higher service" 2 "II: lower service" 3 "IIIa: higher grade routine non-manual" 4 "IVa: small employers" 5 "IVb: independent" ///
	6 "IIIb: lower grade routine non-manual" 7 "V: manual foremen" 8 "VI: skilled manual" 9 "VIIa: semi-unskilled manual" 10 "VIIb: farm workers" 11 "IVc: farmers, farm managers"
label values faclass class11

recode faclass (1=1) (2=2) (3=3) (4/5=4) (6=7) (7/8=6) (9/10=7) (11=5), ge(faclass7)
label var faclass7 "father's class (EGP): 7 categories"
label define class7 1 "I" 2 "II" 3 "IIIa" 4 "IVa+IVb" 5 "IVc" 6 "V+VI"  7 "IIIb+VIIa+VIIb"
label values faclass7 class7

rename q0220213 maocc
label var maocc "mother's occupation at age 14"

* mother's occupation
ge maisei=.
replace	maisei=	77	if	maocc==	11
replace	maisei=	77	if	maocc==	12
replace	maisei=	58	if	maocc==	13
replace	maisei=	70	if	maocc==	21
replace	maisei=	67	if	maocc==	22
replace	maisei=	67	if	maocc==	23
replace	maisei=	61	if	maocc==	24
replace	maisei=	51	if	maocc==	30
replace	maisei=	69	if	maocc==	111
replace	maisei=	78	if	maocc==	112
replace	maisei=	65	if	maocc==	113
replace	maisei=	71	if	maocc==	120
replace	maisei=	69	if	maocc==	131
replace	maisei=	68	if	maocc==	132
replace	maisei=	71	if	maocc==	133
replace	maisei=	56	if	maocc==	134
replace	maisei=	69	if	maocc==	135
replace	maisei=	85	if	maocc==	141
replace	maisei=	74	if	maocc==	142
replace	maisei=	43	if	maocc==	143
replace	maisei=	85	if	maocc==	144
replace	maisei=	85	if	maocc==	145
replace	maisei=	77	if	maocc==	151
replace	maisei=	69	if	maocc==	152
replace	maisei=	66	if	maocc==	153
replace	maisei=	43	if	maocc==	154
replace	maisei=	66	if	maocc==	155
replace	maisei=	66	if	maocc==	156
replace	maisei=	66	if	maocc==	157
replace	maisei=	68	if	maocc==	161
replace	maisei=	69	if	maocc==	162
replace	maisei=	69	if	maocc==	163
replace	maisei=	69	if	maocc==	164
replace	maisei=	69	if	maocc==	165
replace	maisei=	85	if	maocc==	171
replace	maisei=	51	if	maocc==	172
replace	maisei=	53	if	maocc==	173
replace	maisei=	65	if	maocc==	181
replace	maisei=	65	if	maocc==	182
replace	maisei=	64	if	maocc==	183
replace	maisei=	64	if	maocc==	184
replace	maisei=	49	if	maocc==	211
replace	maisei=	50	if	maocc==	212
replace	maisei=	55	if	maocc==	213
replace	maisei=	52	if	maocc==	220
replace	maisei=	49	if	maocc==	231
replace	maisei=	46	if	maocc==	232
replace	maisei=	54	if	maocc==	233
replace	maisei=	51	if	maocc==	234
replace	maisei=	52	if	maocc==	235
replace	maisei=	57	if	maocc==	236
replace	maisei=	50	if	maocc==	237
replace	maisei=	49	if	maocc==	238
replace	maisei=	51	if	maocc==	241
replace	maisei=	51	if	maocc==	242
replace	maisei=	49	if	maocc==	243
replace	maisei=	38	if	maocc==	251
replace	maisei=	38	if	maocc==	252
replace	maisei=	38	if	maocc==	253
replace	maisei=	55	if	maocc==	261
replace	maisei=	55	if	maocc==	262
replace	maisei=	55	if	maocc==	263
replace	maisei=	43	if	maocc==	271
replace	maisei=	38	if	maocc==	272
replace	maisei=	52	if	maocc==	281
replace	maisei=	54	if	maocc==	282
replace	maisei=	52	if	maocc==	283
replace	maisei=	54	if	maocc==	291
replace	maisei=	59	if	maocc==	292
replace	maisei=	56	if	maocc==	293
replace	maisei=	45	if	maocc==	311
replace	maisei=	45	if	maocc==	312
replace	maisei=	45	if	maocc==	313
replace	maisei=	45	if	maocc==	314
replace	maisei=	51	if	maocc==	315
replace	maisei=	36	if	maocc==	316
replace	maisei=	39	if	maocc==	317
replace	maisei=	39	if	maocc==	318
replace	maisei=	46	if	maocc==	321
replace	maisei=	52	if	maocc==	322
replace	maisei=	49	if	maocc==	323
replace	maisei=	38	if	maocc==	411
replace	maisei=	29	if	maocc==	412
replace	maisei=	30	if	maocc==	413
replace	maisei=	54	if	maocc==	414
replace	maisei=	38	if	maocc==	415
replace	maisei=	30	if	maocc==	416
replace	maisei=	30	if	maocc==	421
replace	maisei=	34	if	maocc==	422
replace	maisei=	19	if	maocc==	431
replace	maisei=	34	if	maocc==	432
replace	maisei=	50	if	maocc==	441
replace	maisei=	42	if	maocc==	442
replace	maisei=	40	if	maocc==	443
replace	maisei=	40	if	maocc==	444
replace	maisei=	43	if	maocc==	511
replace	maisei=	43	if	maocc==	512
replace	maisei=	37	if	maocc==	513
replace	maisei=	43	if	maocc==	521
replace	maisei=	43	if	maocc==	522
replace	maisei=	43	if	maocc==	530
replace	maisei=	23	if	maocc==	611
replace	maisei=	23	if	maocc==	612
replace	maisei=	23	if	maocc==	613
replace	maisei=	23	if	maocc==	614
replace	maisei=	23	if	maocc==	615
replace	maisei=	23	if	maocc==	616
replace	maisei=	23	if	maocc==	617
replace	maisei=	28	if	maocc==	618
replace	maisei=	22	if	maocc==	620
replace	maisei=	28	if	maocc==	630
replace	maisei=	30	if	maocc==	711
replace	maisei=	30	if	maocc==	712
replace	maisei=	34	if	maocc==	713
replace	maisei=	29	if	maocc==	714
replace	maisei=	31	if	maocc==	721
replace	maisei=	35	if	maocc==	722
replace	maisei=	34	if	maocc==	731
replace	maisei=	34	if	maocc==	732
replace	maisei=	40	if	maocc==	733
replace	maisei=	38	if	maocc==	741
replace	maisei=	28	if	maocc==	742
replace	maisei=	29	if	maocc==	743
replace	maisei=	40	if	maocc==	744
replace	maisei=	30	if	maocc==	751
replace	maisei=	33	if	maocc==	752
replace	maisei=	36	if	maocc==	753
replace	maisei=	31	if	maocc==	754
replace	maisei=	35	if	maocc==	811
replace	maisei=	30	if	maocc==	812
replace	maisei=	22	if	maocc==	813
replace	maisei=	27	if	maocc==	814
replace	maisei=	35	if	maocc==	815
replace	maisei=	32	if	maocc==	816
replace	maisei=	26	if	maocc==	817
replace	maisei=	36	if	maocc==	821
replace	maisei=	30	if	maocc==	822
replace	maisei=	30	if	maocc==	823
replace	maisei=	29	if	maocc==	824
replace	maisei=	38	if	maocc==	825
replace	maisei=	30	if	maocc==	826
replace	maisei=	29	if	maocc==	827
replace	maisei=	29	if	maocc==	828
replace	maisei=	26	if	maocc==	829
replace	maisei=	31	if	maocc==	831
replace	maisei=	34	if	maocc==	832
replace	maisei=	30	if	maocc==	833
replace	maisei=	36	if	maocc==	841
replace	maisei=	34	if	maocc==	842
replace	maisei=	26	if	maocc==	843
replace	maisei=	32	if	maocc==	844
replace	maisei=	16	if	maocc==	911
replace	maisei=	23	if	maocc==	912
replace	maisei=	27	if	maocc==	913
replace	maisei=	23	if	maocc==	914
replace	maisei=	23	if	maocc==	915
replace	maisei=	16	if	maocc==	920
replace	maisei=	20	if	maocc==	930
replace	maisei=	21	if	maocc==	941
replace	maisei=	29	if	maocc==	942
replace	maisei=	56	if	maocc==	943
replace	maisei=	40	if	maocc==	944
replace	maisei=	.	if	maocc==	999
label var maisei "mother's occupational status (ISEI) at age 14"

ge maclass=.
replace	maclass=	1	if	maocc==	11
replace	maclass=	1	if	maocc==	12
replace	maclass=	2	if	maocc==	13
replace	maclass=	1	if	maocc==	21
replace	maclass=	1	if	maocc==	22
replace	maclass=	1	if	maocc==	23
replace	maclass=	1	if	maocc==	24
replace	maclass=	2	if	maocc==	30
replace	maclass=	1	if	maocc==	111
replace	maclass=	1	if	maocc==	112
replace	maclass=	1	if	maocc==	113
replace	maclass=	1	if	maocc==	120
replace	maclass=	1	if	maocc==	131
replace	maclass=	1	if	maocc==	132
replace	maclass=	1	if	maocc==	133
replace	maclass=	2	if	maocc==	134
replace	maclass=	1	if	maocc==	135
replace	maclass=	1	if	maocc==	141
replace	maclass=	1	if	maocc==	142
replace	maclass=	2	if	maocc==	143
replace	maclass=	1	if	maocc==	144
replace	maclass=	1	if	maocc==	145
replace	maclass=	1	if	maocc==	151
replace	maclass=	2	if	maocc==	152
replace	maclass=	2	if	maocc==	153
replace	maclass=	2	if	maocc==	154
replace	maclass=	2	if	maocc==	155
replace	maclass=	1	if	maocc==	156
replace	maclass=	1	if	maocc==	157
replace	maclass=	1	if	maocc==	161
replace	maclass=	1	if	maocc==	162
replace	maclass=	2	if	maocc==	163
replace	maclass=	2	if	maocc==	164
replace	maclass=	2	if	maocc==	165
replace	maclass=	1	if	maocc==	171
replace	maclass=	2	if	maocc==	172
replace	maclass=	2	if	maocc==	173
replace	maclass=	2	if	maocc==	181
replace	maclass=	2	if	maocc==	182
replace	maclass=	2	if	maocc==	183
replace	maclass=	2	if	maocc==	184
replace	maclass=	2	if	maocc==	211
replace	maclass=	2	if	maocc==	212
replace	maclass=	2	if	maocc==	213
replace	maclass=	2	if	maocc==	220
replace	maclass=	2	if	maocc==	231
replace	maclass=	2	if	maocc==	232
replace	maclass=	2	if	maocc==	233
replace	maclass=	2	if	maocc==	234
replace	maclass=	2	if	maocc==	235
replace	maclass=	2	if	maocc==	236
replace	maclass=	2	if	maocc==	237
replace	maclass=	2	if	maocc==	238
replace	maclass=	2	if	maocc==	241
replace	maclass=	2	if	maocc==	242
replace	maclass=	2	if	maocc==	243
replace	maclass=	3	if	maocc==	251
replace	maclass=	3	if	maocc==	252
replace	maclass=	3	if	maocc==	253
replace	maclass=	2	if	maocc==	261
replace	maclass=	2	if	maocc==	262
replace	maclass=	2	if	maocc==	263
replace	maclass=	3	if	maocc==	271
replace	maclass=	3	if	maocc==	272
replace	maclass=	2	if	maocc==	281
replace	maclass=	2	if	maocc==	282
replace	maclass=	2	if	maocc==	283
replace	maclass=	3	if	maocc==	291
replace	maclass=	2	if	maocc==	292
replace	maclass=	2	if	maocc==	293
replace	maclass=	3	if	maocc==	311
replace	maclass=	3	if	maocc==	312
replace	maclass=	3	if	maocc==	313
replace	maclass=	3	if	maocc==	314
replace	maclass=	3	if	maocc==	315
replace	maclass=	3	if	maocc==	316
replace	maclass=	3	if	maocc==	317
replace	maclass=	3	if	maocc==	318
replace	maclass=	3	if	maocc==	321
replace	maclass=	3	if	maocc==	322
replace	maclass=	3	if	maocc==	323
replace	maclass=	3	if	maocc==	411
replace	maclass=	8	if	maocc==	412
replace	maclass=	2	if	maocc==	413
replace	maclass=	8	if	maocc==	414
replace	maclass=	3	if	maocc==	415
replace	maclass=	8	if	maocc==	416
replace	maclass=	8	if	maocc==	421
replace	maclass=	9	if	maocc==	422
replace	maclass=	9	if	maocc==	431
replace	maclass=	3	if	maocc==	432
replace	maclass=	8	if	maocc==	441
replace	maclass=	8	if	maocc==	442
replace	maclass=	9	if	maocc==	443
replace	maclass=	9	if	maocc==	444
replace	maclass=	3	if	maocc==	511
replace	maclass=	3	if	maocc==	512
replace	maclass=	3	if	maocc==	513
replace	maclass=	3	if	maocc==	521
replace	maclass=	3	if	maocc==	522
replace	maclass=	3	if	maocc==	530
replace	maclass=	10	if	maocc==	611
replace	maclass=	10	if	maocc==	612
replace	maclass=	10	if	maocc==	613
replace	maclass=	10	if	maocc==	614
replace	maclass=	10	if	maocc==	615
replace	maclass=	10	if	maocc==	616
replace	maclass=	10	if	maocc==	617
replace	maclass=	10	if	maocc==	618
replace	maclass=	10	if	maocc==	620
replace	maclass=	10	if	maocc==	630
replace	maclass=	9	if	maocc==	711
replace	maclass=	8	if	maocc==	712
replace	maclass=	8	if	maocc==	713
replace	maclass=	8	if	maocc==	714
replace	maclass=	8	if	maocc==	721
replace	maclass=	8	if	maocc==	722
replace	maclass=	8	if	maocc==	731
replace	maclass=	8	if	maocc==	732
replace	maclass=	8	if	maocc==	733
replace	maclass=	8	if	maocc==	741
replace	maclass=	9	if	maocc==	742
replace	maclass=	9	if	maocc==	743
replace	maclass=	8	if	maocc==	744
replace	maclass=	8	if	maocc==	751
replace	maclass=	8	if	maocc==	752
replace	maclass=	8	if	maocc==	753
replace	maclass=	8	if	maocc==	754
replace	maclass=	9	if	maocc==	811
replace	maclass=	9	if	maocc==	812
replace	maclass=	9	if	maocc==	813
replace	maclass=	9	if	maocc==	814
replace	maclass=	8	if	maocc==	815
replace	maclass=	8	if	maocc==	816
replace	maclass=	8	if	maocc==	817
replace	maclass=	9	if	maocc==	821
replace	maclass=	9	if	maocc==	822
replace	maclass=	9	if	maocc==	823
replace	maclass=	9	if	maocc==	824
replace	maclass=	9	if	maocc==	825
replace	maclass=	9	if	maocc==	826
replace	maclass=	9	if	maocc==	827
replace	maclass=	9	if	maocc==	828
replace	maclass=	9	if	maocc==	829
replace	maclass=	9	if	maocc==	831
replace	maclass=	9	if	maocc==	832
replace	maclass=	9	if	maocc==	833
replace	maclass=	9	if	maocc==	841
replace	maclass=	9	if	maocc==	842
replace	maclass=	9	if	maocc==	843
replace	maclass=	9	if	maocc==	844
replace	maclass=	9	if	maocc==	911
replace	maclass=	9	if	maocc==	912
replace	maclass=	9	if	maocc==	913
replace	maclass=	9	if	maocc==	914
replace	maclass=	9	if	maocc==	915
replace	maclass=	10	if	maocc==	920
replace	maclass=	9	if	maocc==	930
replace	maclass=	9	if	maocc==	941
replace	maclass=	9	if	maocc==	942
replace	maclass=	7	if	maocc==	943
replace	maclass=	8	if	maocc==	944
replace	maclass=	.	if	maocc==	999

replace maclass=6 if maclass==3 & (q0220206==1 | q0220206>4) & q0220206!=.
replace maclass=10 if q0220212==1 | q0220212==2
replace maclass=4 if q0220211==4 & maclass!=1 & maclass!=10
replace maclass=5 if q0220211==5 & maclass!=10
replace maclass=11 if maclass==10 & ((q0220211==4 | q0220211==5) | (q0220206==2 | q0220206==3 | q0220206==4))

label var maclass "mother's class (EGP) at age 14"
label values maclass class11

recode maclass (1=1) (2=2) (3=3) (4/5=4) (6=7) (7/8=6) (9/10=7) (11=5), ge(maclass7)
label var maclass7 "mother's class (EGP): 7 categories"
label values maclass7 class7

ge pisei = faisei
replace pisei = maisei if faisei==.
label var pisei "parental occupational status (ISEI)"

ge pclass=faclass7
replace pclass=maclass7 if faclass7==.
label var pclass "parental class (EGP7)"
label values pclass class7


*first occupation
rename r0250118 firstocc
label var firstocc "respondent's first occupation"

ge firstisei=.
replace	firstisei=	77	if	firstocc==	11
replace	firstisei=	77	if	firstocc==	12
replace	firstisei=	58	if	firstocc==	13
replace	firstisei=	70	if	firstocc==	21
replace	firstisei=	67	if	firstocc==	22
replace	firstisei=	67	if	firstocc==	23
replace	firstisei=	61	if	firstocc==	24
replace	firstisei=	51	if	firstocc==	30
replace	firstisei=	69	if	firstocc==	111
replace	firstisei=	78	if	firstocc==	112
replace	firstisei=	65	if	firstocc==	113
replace	firstisei=	71	if	firstocc==	120
replace	firstisei=	69	if	firstocc==	131
replace	firstisei=	68	if	firstocc==	132
replace	firstisei=	71	if	firstocc==	133
replace	firstisei=	56	if	firstocc==	134
replace	firstisei=	69	if	firstocc==	135
replace	firstisei=	85	if	firstocc==	141
replace	firstisei=	74	if	firstocc==	142
replace	firstisei=	43	if	firstocc==	143
replace	firstisei=	85	if	firstocc==	144
replace	firstisei=	85	if	firstocc==	145
replace	firstisei=	77	if	firstocc==	151
replace	firstisei=	69	if	firstocc==	152
replace	firstisei=	66	if	firstocc==	153
replace	firstisei=	43	if	firstocc==	154
replace	firstisei=	66	if	firstocc==	155
replace	firstisei=	66	if	firstocc==	156
replace	firstisei=	66	if	firstocc==	157
replace	firstisei=	68	if	firstocc==	161
replace	firstisei=	69	if	firstocc==	162
replace	firstisei=	69	if	firstocc==	163
replace	firstisei=	69	if	firstocc==	164
replace	firstisei=	69	if	firstocc==	165
replace	firstisei=	85	if	firstocc==	171
replace	firstisei=	51	if	firstocc==	172
replace	firstisei=	53	if	firstocc==	173
replace	firstisei=	65	if	firstocc==	181
replace	firstisei=	65	if	firstocc==	182
replace	firstisei=	64	if	firstocc==	183
replace	firstisei=	64	if	firstocc==	184
replace	firstisei=	49	if	firstocc==	211
replace	firstisei=	50	if	firstocc==	212
replace	firstisei=	55	if	firstocc==	213
replace	firstisei=	52	if	firstocc==	220
replace	firstisei=	49	if	firstocc==	231
replace	firstisei=	46	if	firstocc==	232
replace	firstisei=	54	if	firstocc==	233
replace	firstisei=	51	if	firstocc==	234
replace	firstisei=	52	if	firstocc==	235
replace	firstisei=	57	if	firstocc==	236
replace	firstisei=	50	if	firstocc==	237
replace	firstisei=	49	if	firstocc==	238
replace	firstisei=	51	if	firstocc==	241
replace	firstisei=	51	if	firstocc==	242
replace	firstisei=	49	if	firstocc==	243
replace	firstisei=	38	if	firstocc==	251
replace	firstisei=	38	if	firstocc==	252
replace	firstisei=	38	if	firstocc==	253
replace	firstisei=	55	if	firstocc==	261
replace	firstisei=	55	if	firstocc==	262
replace	firstisei=	55	if	firstocc==	263
replace	firstisei=	43	if	firstocc==	271
replace	firstisei=	38	if	firstocc==	272
replace	firstisei=	52	if	firstocc==	281
replace	firstisei=	54	if	firstocc==	282
replace	firstisei=	52	if	firstocc==	283
replace	firstisei=	54	if	firstocc==	291
replace	firstisei=	59	if	firstocc==	292
replace	firstisei=	56	if	firstocc==	293
replace	firstisei=	45	if	firstocc==	311
replace	firstisei=	45	if	firstocc==	312
replace	firstisei=	45	if	firstocc==	313
replace	firstisei=	45	if	firstocc==	314
replace	firstisei=	51	if	firstocc==	315
replace	firstisei=	36	if	firstocc==	316
replace	firstisei=	39	if	firstocc==	317
replace	firstisei=	39	if	firstocc==	318
replace	firstisei=	46	if	firstocc==	321
replace	firstisei=	52	if	firstocc==	322
replace	firstisei=	49	if	firstocc==	323
replace	firstisei=	38	if	firstocc==	411
replace	firstisei=	29	if	firstocc==	412
replace	firstisei=	30	if	firstocc==	413
replace	firstisei=	54	if	firstocc==	414
replace	firstisei=	38	if	firstocc==	415
replace	firstisei=	30	if	firstocc==	416
replace	firstisei=	30	if	firstocc==	421
replace	firstisei=	34	if	firstocc==	422
replace	firstisei=	19	if	firstocc==	431
replace	firstisei=	34	if	firstocc==	432
replace	firstisei=	50	if	firstocc==	441
replace	firstisei=	42	if	firstocc==	442
replace	firstisei=	40	if	firstocc==	443
replace	firstisei=	40	if	firstocc==	444
replace	firstisei=	43	if	firstocc==	511
replace	firstisei=	43	if	firstocc==	512
replace	firstisei=	37	if	firstocc==	513
replace	firstisei=	43	if	firstocc==	521
replace	firstisei=	43	if	firstocc==	522
replace	firstisei=	43	if	firstocc==	530
replace	firstisei=	23	if	firstocc==	611
replace	firstisei=	23	if	firstocc==	612
replace	firstisei=	23	if	firstocc==	613
replace	firstisei=	23	if	firstocc==	614
replace	firstisei=	23	if	firstocc==	615
replace	firstisei=	23	if	firstocc==	616
replace	firstisei=	23	if	firstocc==	617
replace	firstisei=	28	if	firstocc==	618
replace	firstisei=	22	if	firstocc==	620
replace	firstisei=	28	if	firstocc==	630
replace	firstisei=	30	if	firstocc==	711
replace	firstisei=	30	if	firstocc==	712
replace	firstisei=	34	if	firstocc==	713
replace	firstisei=	29	if	firstocc==	714
replace	firstisei=	31	if	firstocc==	721
replace	firstisei=	35	if	firstocc==	722
replace	firstisei=	34	if	firstocc==	731
replace	firstisei=	34	if	firstocc==	732
replace	firstisei=	40	if	firstocc==	733
replace	firstisei=	38	if	firstocc==	741
replace	firstisei=	28	if	firstocc==	742
replace	firstisei=	29	if	firstocc==	743
replace	firstisei=	40	if	firstocc==	744
replace	firstisei=	30	if	firstocc==	751
replace	firstisei=	33	if	firstocc==	752
replace	firstisei=	36	if	firstocc==	753
replace	firstisei=	31	if	firstocc==	754
replace	firstisei=	35	if	firstocc==	811
replace	firstisei=	30	if	firstocc==	812
replace	firstisei=	22	if	firstocc==	813
replace	firstisei=	27	if	firstocc==	814
replace	firstisei=	35	if	firstocc==	815
replace	firstisei=	32	if	firstocc==	816
replace	firstisei=	26	if	firstocc==	817
replace	firstisei=	36	if	firstocc==	821
replace	firstisei=	30	if	firstocc==	822
replace	firstisei=	30	if	firstocc==	823
replace	firstisei=	29	if	firstocc==	824
replace	firstisei=	38	if	firstocc==	825
replace	firstisei=	30	if	firstocc==	826
replace	firstisei=	29	if	firstocc==	827
replace	firstisei=	29	if	firstocc==	828
replace	firstisei=	26	if	firstocc==	829
replace	firstisei=	31	if	firstocc==	831
replace	firstisei=	34	if	firstocc==	832
replace	firstisei=	30	if	firstocc==	833
replace	firstisei=	36	if	firstocc==	841
replace	firstisei=	34	if	firstocc==	842
replace	firstisei=	26	if	firstocc==	843
replace	firstisei=	32	if	firstocc==	844
replace	firstisei=	16	if	firstocc==	911
replace	firstisei=	23	if	firstocc==	912
replace	firstisei=	27	if	firstocc==	913
replace	firstisei=	23	if	firstocc==	914
replace	firstisei=	23	if	firstocc==	915
replace	firstisei=	16	if	firstocc==	920
replace	firstisei=	20	if	firstocc==	930
replace	firstisei=	21	if	firstocc==	941
replace	firstisei=	29	if	firstocc==	942
replace	firstisei=	56	if	firstocc==	943
replace	firstisei=	40	if	firstocc==	944
replace	firstisei=	.	if	firstocc==	999
label var firstisei "respondent's first occupational status (ISEI)"

ge firstclass=.
replace	firstclass=	1	if	firstocc==	11
replace	firstclass=	1	if	firstocc==	12
replace	firstclass=	2	if	firstocc==	13
replace	firstclass=	1	if	firstocc==	21
replace	firstclass=	1	if	firstocc==	22
replace	firstclass=	1	if	firstocc==	23
replace	firstclass=	1	if	firstocc==	24
replace	firstclass=	2	if	firstocc==	30
replace	firstclass=	1	if	firstocc==	111
replace	firstclass=	1	if	firstocc==	112
replace	firstclass=	1	if	firstocc==	113
replace	firstclass=	1	if	firstocc==	120
replace	firstclass=	1	if	firstocc==	131
replace	firstclass=	1	if	firstocc==	132
replace	firstclass=	1	if	firstocc==	133
replace	firstclass=	2	if	firstocc==	134
replace	firstclass=	1	if	firstocc==	135
replace	firstclass=	1	if	firstocc==	141
replace	firstclass=	1	if	firstocc==	142
replace	firstclass=	2	if	firstocc==	143
replace	firstclass=	1	if	firstocc==	144
replace	firstclass=	1	if	firstocc==	145
replace	firstclass=	1	if	firstocc==	151
replace	firstclass=	2	if	firstocc==	152
replace	firstclass=	2	if	firstocc==	153
replace	firstclass=	2	if	firstocc==	154
replace	firstclass=	2	if	firstocc==	155
replace	firstclass=	1	if	firstocc==	156
replace	firstclass=	1	if	firstocc==	157
replace	firstclass=	1	if	firstocc==	161
replace	firstclass=	1	if	firstocc==	162
replace	firstclass=	2	if	firstocc==	163
replace	firstclass=	2	if	firstocc==	164
replace	firstclass=	2	if	firstocc==	165
replace	firstclass=	1	if	firstocc==	171
replace	firstclass=	2	if	firstocc==	172
replace	firstclass=	2	if	firstocc==	173
replace	firstclass=	2	if	firstocc==	181
replace	firstclass=	2	if	firstocc==	182
replace	firstclass=	2	if	firstocc==	183
replace	firstclass=	2	if	firstocc==	184
replace	firstclass=	2	if	firstocc==	211
replace	firstclass=	2	if	firstocc==	212
replace	firstclass=	2	if	firstocc==	213
replace	firstclass=	2	if	firstocc==	220
replace	firstclass=	2	if	firstocc==	231
replace	firstclass=	2	if	firstocc==	232
replace	firstclass=	2	if	firstocc==	233
replace	firstclass=	2	if	firstocc==	234
replace	firstclass=	2	if	firstocc==	235
replace	firstclass=	2	if	firstocc==	236
replace	firstclass=	2	if	firstocc==	237
replace	firstclass=	2	if	firstocc==	238
replace	firstclass=	2	if	firstocc==	241
replace	firstclass=	2	if	firstocc==	242
replace	firstclass=	2	if	firstocc==	243
replace	firstclass=	3	if	firstocc==	251
replace	firstclass=	3	if	firstocc==	252
replace	firstclass=	3	if	firstocc==	253
replace	firstclass=	2	if	firstocc==	261
replace	firstclass=	2	if	firstocc==	262
replace	firstclass=	2	if	firstocc==	263
replace	firstclass=	3	if	firstocc==	271
replace	firstclass=	3	if	firstocc==	272
replace	firstclass=	2	if	firstocc==	281
replace	firstclass=	2	if	firstocc==	282
replace	firstclass=	2	if	firstocc==	283
replace	firstclass=	3	if	firstocc==	291
replace	firstclass=	2	if	firstocc==	292
replace	firstclass=	2	if	firstocc==	293
replace	firstclass=	3	if	firstocc==	311
replace	firstclass=	3	if	firstocc==	312
replace	firstclass=	3	if	firstocc==	313
replace	firstclass=	3	if	firstocc==	314
replace	firstclass=	3	if	firstocc==	315
replace	firstclass=	3	if	firstocc==	316
replace	firstclass=	3	if	firstocc==	317
replace	firstclass=	3	if	firstocc==	318
replace	firstclass=	3	if	firstocc==	321
replace	firstclass=	3	if	firstocc==	322
replace	firstclass=	3	if	firstocc==	323
replace	firstclass=	3	if	firstocc==	411
replace	firstclass=	8	if	firstocc==	412
replace	firstclass=	2	if	firstocc==	413
replace	firstclass=	8	if	firstocc==	414
replace	firstclass=	3	if	firstocc==	415
replace	firstclass=	8	if	firstocc==	416
replace	firstclass=	8	if	firstocc==	421
replace	firstclass=	9	if	firstocc==	422
replace	firstclass=	9	if	firstocc==	431
replace	firstclass=	3	if	firstocc==	432
replace	firstclass=	8	if	firstocc==	441
replace	firstclass=	8	if	firstocc==	442
replace	firstclass=	9	if	firstocc==	443
replace	firstclass=	9	if	firstocc==	444
replace	firstclass=	3	if	firstocc==	511
replace	firstclass=	3	if	firstocc==	512
replace	firstclass=	3	if	firstocc==	513
replace	firstclass=	3	if	firstocc==	521
replace	firstclass=	3	if	firstocc==	522
replace	firstclass=	3	if	firstocc==	530
replace	firstclass=	10	if	firstocc==	611
replace	firstclass=	10	if	firstocc==	612
replace	firstclass=	10	if	firstocc==	613
replace	firstclass=	10	if	firstocc==	614
replace	firstclass=	10	if	firstocc==	615
replace	firstclass=	10	if	firstocc==	616
replace	firstclass=	10	if	firstocc==	617
replace	firstclass=	10	if	firstocc==	618
replace	firstclass=	10	if	firstocc==	620
replace	firstclass=	10	if	firstocc==	630
replace	firstclass=	9	if	firstocc==	711
replace	firstclass=	8	if	firstocc==	712
replace	firstclass=	8	if	firstocc==	713
replace	firstclass=	8	if	firstocc==	714
replace	firstclass=	8	if	firstocc==	721
replace	firstclass=	8	if	firstocc==	722
replace	firstclass=	8	if	firstocc==	731
replace	firstclass=	8	if	firstocc==	732
replace	firstclass=	8	if	firstocc==	733
replace	firstclass=	8	if	firstocc==	741
replace	firstclass=	9	if	firstocc==	742
replace	firstclass=	9	if	firstocc==	743
replace	firstclass=	8	if	firstocc==	744
replace	firstclass=	8	if	firstocc==	751
replace	firstclass=	8	if	firstocc==	752
replace	firstclass=	8	if	firstocc==	753
replace	firstclass=	8	if	firstocc==	754
replace	firstclass=	9	if	firstocc==	811
replace	firstclass=	9	if	firstocc==	812
replace	firstclass=	9	if	firstocc==	813
replace	firstclass=	9	if	firstocc==	814
replace	firstclass=	8	if	firstocc==	815
replace	firstclass=	8	if	firstocc==	816
replace	firstclass=	8	if	firstocc==	817
replace	firstclass=	9	if	firstocc==	821
replace	firstclass=	9	if	firstocc==	822
replace	firstclass=	9	if	firstocc==	823
replace	firstclass=	9	if	firstocc==	824
replace	firstclass=	9	if	firstocc==	825
replace	firstclass=	9	if	firstocc==	826
replace	firstclass=	9	if	firstocc==	827
replace	firstclass=	9	if	firstocc==	828
replace	firstclass=	9	if	firstocc==	829
replace	firstclass=	9	if	firstocc==	831
replace	firstclass=	9	if	firstocc==	832
replace	firstclass=	9	if	firstocc==	833
replace	firstclass=	9	if	firstocc==	841
replace	firstclass=	9	if	firstocc==	842
replace	firstclass=	9	if	firstocc==	843
replace	firstclass=	9	if	firstocc==	844
replace	firstclass=	9	if	firstocc==	911
replace	firstclass=	9	if	firstocc==	912
replace	firstclass=	9	if	firstocc==	913
replace	firstclass=	9	if	firstocc==	914
replace	firstclass=	9	if	firstocc==	915
replace	firstclass=	10	if	firstocc==	920
replace	firstclass=	9	if	firstocc==	930
replace	firstclass=	9	if	firstocc==	941
replace	firstclass=	9	if	firstocc==	942
replace	firstclass=	7	if	firstocc==	943
replace	firstclass=	8	if	firstocc==	944
replace	firstclass=	.	if	firstocc==	999

replace firstclass=6 if firstclass==3 & (r0250109==1 | r0250109>4) & r0250109!=.
replace firstclass=10 if r0250117==1 | r0250117==2
replace firstclass=4 if r0250114==4 & firstclass!=1 & firstclass!=10
replace firstclass=5 if r0250114==5 & firstclass!=10
replace firstclass=11 if firstclass==10 & ((r0250114==4 | r0250114==5) | (r0250109==2 | r0250109==3 | r0250109==4))

label var firstclass "respondent's first class (EGP)"
label values firstclass class11

recode firstclass (1=1) (2=2) (3=3) (4/5=4) (6=7) (7/8=6) (9/10=7) (11=5), ge(firstclass7)
label var firstclass7 "respondent's first class (EGP): 7 categories"
label values firstclass7 class7


* mature occupation (45/40/current:36~45/current:26~35)
ge emp=ra190001 if year==2008
replace emp=rd230001 if year==2009
replace emp=r0250201 if year==2010 | year==2011
recode emp 2/.=0
label var emp "employed"

replace r0250202=. if r0250202==9999
ge unempduration=year-r0250202

replace emp=1 if emp==0 & (year==2010 | year==2011) & unempduration<=2 & r0250000==1

ge occ=ra190013 if year==2008
replace occ=rd230013 if year==2009
replace occ=r0250219 if year==2010 | year==2011

ge position=ra190005 if year==2008
replace position=rd230005 if year==2009
replace position=r0250210 if year==2010 | year==2011

ge status=ra190010 if year==2008
replace status=rd230010 if year==2009
replace status=r0250215 if year==2010 | year==2011

ge ind=ra190012 if year==2008
replace ind=rd230012 if year==2009
replace ind=r0250218 if year==2010 | year==2011

label var occ "respondent's mature occupation"

ge isei=.
replace	isei=	77	if	occ==	11
replace	isei=	77	if	occ==	12
replace	isei=	58	if	occ==	13
replace	isei=	70	if	occ==	21
replace	isei=	67	if	occ==	22
replace	isei=	67	if	occ==	23
replace	isei=	61	if	occ==	24
replace	isei=	51	if	occ==	30
replace	isei=	69	if	occ==	111
replace	isei=	78	if	occ==	112
replace	isei=	65	if	occ==	113
replace	isei=	71	if	occ==	120
replace	isei=	69	if	occ==	131
replace	isei=	68	if	occ==	132
replace	isei=	71	if	occ==	133
replace	isei=	56	if	occ==	134
replace	isei=	69	if	occ==	135
replace	isei=	85	if	occ==	141
replace	isei=	74	if	occ==	142
replace	isei=	43	if	occ==	143
replace	isei=	85	if	occ==	144
replace	isei=	85	if	occ==	145
replace	isei=	77	if	occ==	151
replace	isei=	69	if	occ==	152
replace	isei=	66	if	occ==	153
replace	isei=	43	if	occ==	154
replace	isei=	66	if	occ==	155
replace	isei=	66	if	occ==	156
replace	isei=	66	if	occ==	157
replace	isei=	68	if	occ==	161
replace	isei=	69	if	occ==	162
replace	isei=	69	if	occ==	163
replace	isei=	69	if	occ==	164
replace	isei=	69	if	occ==	165
replace	isei=	85	if	occ==	171
replace	isei=	51	if	occ==	172
replace	isei=	53	if	occ==	173
replace	isei=	65	if	occ==	181
replace	isei=	65	if	occ==	182
replace	isei=	64	if	occ==	183
replace	isei=	64	if	occ==	184
replace	isei=	49	if	occ==	211
replace	isei=	50	if	occ==	212
replace	isei=	55	if	occ==	213
replace	isei=	52	if	occ==	220
replace	isei=	49	if	occ==	231
replace	isei=	46	if	occ==	232
replace	isei=	54	if	occ==	233
replace	isei=	51	if	occ==	234
replace	isei=	52	if	occ==	235
replace	isei=	57	if	occ==	236
replace	isei=	50	if	occ==	237
replace	isei=	49	if	occ==	238
replace	isei=	51	if	occ==	241
replace	isei=	51	if	occ==	242
replace	isei=	49	if	occ==	243
replace	isei=	38	if	occ==	251
replace	isei=	38	if	occ==	252
replace	isei=	38	if	occ==	253
replace	isei=	55	if	occ==	261
replace	isei=	55	if	occ==	262
replace	isei=	55	if	occ==	263
replace	isei=	43	if	occ==	271
replace	isei=	38	if	occ==	272
replace	isei=	52	if	occ==	281
replace	isei=	54	if	occ==	282
replace	isei=	52	if	occ==	283
replace	isei=	54	if	occ==	291
replace	isei=	59	if	occ==	292
replace	isei=	56	if	occ==	293
replace	isei=	45	if	occ==	311
replace	isei=	45	if	occ==	312
replace	isei=	45	if	occ==	313
replace	isei=	45	if	occ==	314
replace	isei=	51	if	occ==	315
replace	isei=	36	if	occ==	316
replace	isei=	39	if	occ==	317
replace	isei=	39	if	occ==	318
replace	isei=	46	if	occ==	321
replace	isei=	52	if	occ==	322
replace	isei=	49	if	occ==	323
replace	isei=	38	if	occ==	411
replace	isei=	29	if	occ==	412
replace	isei=	30	if	occ==	413
replace	isei=	54	if	occ==	414
replace	isei=	38	if	occ==	415
replace	isei=	30	if	occ==	416
replace	isei=	30	if	occ==	421
replace	isei=	34	if	occ==	422
replace	isei=	19	if	occ==	431
replace	isei=	34	if	occ==	432
replace	isei=	50	if	occ==	441
replace	isei=	42	if	occ==	442
replace	isei=	40	if	occ==	443
replace	isei=	40	if	occ==	444
replace	isei=	43	if	occ==	511
replace	isei=	43	if	occ==	512
replace	isei=	37	if	occ==	513
replace	isei=	43	if	occ==	521
replace	isei=	43	if	occ==	522
replace	isei=	43	if	occ==	530
replace	isei=	23	if	occ==	611
replace	isei=	23	if	occ==	612
replace	isei=	23	if	occ==	613
replace	isei=	23	if	occ==	614
replace	isei=	23	if	occ==	615
replace	isei=	23	if	occ==	616
replace	isei=	23	if	occ==	617
replace	isei=	28	if	occ==	618
replace	isei=	22	if	occ==	620
replace	isei=	28	if	occ==	630
replace	isei=	30	if	occ==	711
replace	isei=	30	if	occ==	712
replace	isei=	34	if	occ==	713
replace	isei=	29	if	occ==	714
replace	isei=	31	if	occ==	721
replace	isei=	35	if	occ==	722
replace	isei=	34	if	occ==	731
replace	isei=	34	if	occ==	732
replace	isei=	40	if	occ==	733
replace	isei=	38	if	occ==	741
replace	isei=	28	if	occ==	742
replace	isei=	29	if	occ==	743
replace	isei=	40	if	occ==	744
replace	isei=	30	if	occ==	751
replace	isei=	33	if	occ==	752
replace	isei=	36	if	occ==	753
replace	isei=	31	if	occ==	754
replace	isei=	35	if	occ==	811
replace	isei=	30	if	occ==	812
replace	isei=	22	if	occ==	813
replace	isei=	27	if	occ==	814
replace	isei=	35	if	occ==	815
replace	isei=	32	if	occ==	816
replace	isei=	26	if	occ==	817
replace	isei=	36	if	occ==	821
replace	isei=	30	if	occ==	822
replace	isei=	30	if	occ==	823
replace	isei=	29	if	occ==	824
replace	isei=	38	if	occ==	825
replace	isei=	30	if	occ==	826
replace	isei=	29	if	occ==	827
replace	isei=	29	if	occ==	828
replace	isei=	26	if	occ==	829
replace	isei=	31	if	occ==	831
replace	isei=	34	if	occ==	832
replace	isei=	30	if	occ==	833
replace	isei=	36	if	occ==	841
replace	isei=	34	if	occ==	842
replace	isei=	26	if	occ==	843
replace	isei=	32	if	occ==	844
replace	isei=	16	if	occ==	911
replace	isei=	23	if	occ==	912
replace	isei=	27	if	occ==	913
replace	isei=	23	if	occ==	914
replace	isei=	23	if	occ==	915
replace	isei=	16	if	occ==	920
replace	isei=	20	if	occ==	930
replace	isei=	21	if	occ==	941
replace	isei=	29	if	occ==	942
replace	isei=	56	if	occ==	943
replace	isei=	40	if	occ==	944
replace	isei=	.	if	occ==	999
label var isei "respondent's mature occupational status (ISEI)"

ge class=.
replace	class=	1	if	occ==	11
replace	class=	1	if	occ==	12
replace	class=	2	if	occ==	13
replace	class=	1	if	occ==	21
replace	class=	1	if	occ==	22
replace	class=	1	if	occ==	23
replace	class=	1	if	occ==	24
replace	class=	2	if	occ==	30
replace	class=	1	if	occ==	111
replace	class=	1	if	occ==	112
replace	class=	1	if	occ==	113
replace	class=	1	if	occ==	120
replace	class=	1	if	occ==	131
replace	class=	1	if	occ==	132
replace	class=	1	if	occ==	133
replace	class=	2	if	occ==	134
replace	class=	1	if	occ==	135
replace	class=	1	if	occ==	141
replace	class=	1	if	occ==	142
replace	class=	2	if	occ==	143
replace	class=	1	if	occ==	144
replace	class=	1	if	occ==	145
replace	class=	1	if	occ==	151
replace	class=	2	if	occ==	152
replace	class=	2	if	occ==	153
replace	class=	2	if	occ==	154
replace	class=	2	if	occ==	155
replace	class=	1	if	occ==	156
replace	class=	1	if	occ==	157
replace	class=	1	if	occ==	161
replace	class=	1	if	occ==	162
replace	class=	2	if	occ==	163
replace	class=	2	if	occ==	164
replace	class=	2	if	occ==	165
replace	class=	1	if	occ==	171
replace	class=	2	if	occ==	172
replace	class=	2	if	occ==	173
replace	class=	2	if	occ==	181
replace	class=	2	if	occ==	182
replace	class=	2	if	occ==	183
replace	class=	2	if	occ==	184
replace	class=	2	if	occ==	211
replace	class=	2	if	occ==	212
replace	class=	2	if	occ==	213
replace	class=	2	if	occ==	220
replace	class=	2	if	occ==	231
replace	class=	2	if	occ==	232
replace	class=	2	if	occ==	233
replace	class=	2	if	occ==	234
replace	class=	2	if	occ==	235
replace	class=	2	if	occ==	236
replace	class=	2	if	occ==	237
replace	class=	2	if	occ==	238
replace	class=	2	if	occ==	241
replace	class=	2	if	occ==	242
replace	class=	2	if	occ==	243
replace	class=	3	if	occ==	251
replace	class=	3	if	occ==	252
replace	class=	3	if	occ==	253
replace	class=	2	if	occ==	261
replace	class=	2	if	occ==	262
replace	class=	2	if	occ==	263
replace	class=	3	if	occ==	271
replace	class=	3	if	occ==	272
replace	class=	2	if	occ==	281
replace	class=	2	if	occ==	282
replace	class=	2	if	occ==	283
replace	class=	3	if	occ==	291
replace	class=	2	if	occ==	292
replace	class=	2	if	occ==	293
replace	class=	3	if	occ==	311
replace	class=	3	if	occ==	312
replace	class=	3	if	occ==	313
replace	class=	3	if	occ==	314
replace	class=	3	if	occ==	315
replace	class=	3	if	occ==	316
replace	class=	3	if	occ==	317
replace	class=	3	if	occ==	318
replace	class=	3	if	occ==	321
replace	class=	3	if	occ==	322
replace	class=	3	if	occ==	323
replace	class=	3	if	occ==	411
replace	class=	8	if	occ==	412
replace	class=	2	if	occ==	413
replace	class=	8	if	occ==	414
replace	class=	3	if	occ==	415
replace	class=	8	if	occ==	416
replace	class=	8	if	occ==	421
replace	class=	9	if	occ==	422
replace	class=	9	if	occ==	431
replace	class=	3	if	occ==	432
replace	class=	8	if	occ==	441
replace	class=	8	if	occ==	442
replace	class=	9	if	occ==	443
replace	class=	9	if	occ==	444
replace	class=	3	if	occ==	511
replace	class=	3	if	occ==	512
replace	class=	3	if	occ==	513
replace	class=	3	if	occ==	521
replace	class=	3	if	occ==	522
replace	class=	3	if	occ==	530
replace	class=	10	if	occ==	611
replace	class=	10	if	occ==	612
replace	class=	10	if	occ==	613
replace	class=	10	if	occ==	614
replace	class=	10	if	occ==	615
replace	class=	10	if	occ==	616
replace	class=	10	if	occ==	617
replace	class=	10	if	occ==	618
replace	class=	10	if	occ==	620
replace	class=	10	if	occ==	630
replace	class=	9	if	occ==	711
replace	class=	8	if	occ==	712
replace	class=	8	if	occ==	713
replace	class=	8	if	occ==	714
replace	class=	8	if	occ==	721
replace	class=	8	if	occ==	722
replace	class=	8	if	occ==	731
replace	class=	8	if	occ==	732
replace	class=	8	if	occ==	733
replace	class=	8	if	occ==	741
replace	class=	9	if	occ==	742
replace	class=	9	if	occ==	743
replace	class=	8	if	occ==	744
replace	class=	8	if	occ==	751
replace	class=	8	if	occ==	752
replace	class=	8	if	occ==	753
replace	class=	8	if	occ==	754
replace	class=	9	if	occ==	811
replace	class=	9	if	occ==	812
replace	class=	9	if	occ==	813
replace	class=	9	if	occ==	814
replace	class=	8	if	occ==	815
replace	class=	8	if	occ==	816
replace	class=	8	if	occ==	817
replace	class=	9	if	occ==	821
replace	class=	9	if	occ==	822
replace	class=	9	if	occ==	823
replace	class=	9	if	occ==	824
replace	class=	9	if	occ==	825
replace	class=	9	if	occ==	826
replace	class=	9	if	occ==	827
replace	class=	9	if	occ==	828
replace	class=	9	if	occ==	829
replace	class=	9	if	occ==	831
replace	class=	9	if	occ==	832
replace	class=	9	if	occ==	833
replace	class=	9	if	occ==	841
replace	class=	9	if	occ==	842
replace	class=	9	if	occ==	843
replace	class=	9	if	occ==	844
replace	class=	9	if	occ==	911
replace	class=	9	if	occ==	912
replace	class=	9	if	occ==	913
replace	class=	9	if	occ==	914
replace	class=	9	if	occ==	915
replace	class=	10	if	occ==	920
replace	class=	9	if	occ==	930
replace	class=	9	if	occ==	941
replace	class=	9	if	occ==	942
replace	class=	7	if	occ==	943
replace	class=	8	if	occ==	944
replace	class=	.	if	occ==	999

replace class=6 if class==3 & (position==1 | position>4) & position!=.
replace class=10 if ind==1 | ind==2
replace class=4 if status==4 & class!=1 & class!=10
replace class=5 if status==5 & class!=10
replace class=11 if class==10 & ((status==4 | status==5) | (position==2 | position==3 | position==4))

label var class "respondent's mature class (EGP)"
label values class class11

recode class (1=1) (2=2) (3=3) (4/5=4) (6=7) (7/8=6) (9/10=7) (11=5), ge(class7)
label var class7 "respondent's mature class (EGP): 7 categories"
label values class7 class7

ge weight = wt2008 if year==2008
replace weight = wt2009 if year==2009
replace weight = wt2010 if year==2010
replace weight = wt2011 if year==2011
drop wt*


keep pid year birthyr educ_yrs educ faeduc_yrs maeduc_yrs sex nsibs nbro nsis ///
	 weight occ class* isei maocc maisei maclass faocc faisei faclass country

cd /*insert you work directory here*/
saveold /*insert you file name here*/, replace
